﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using StoragePeriod.BLL.FoodTesting;
using StoragePeriod.Model.FoodTesting;

namespace StoragePeriod.Web.FoodTesting
{
    public partial class FoodDirectionEdit : System.Web.UI.Page
    {
        T_FoodDirection tFoodDirection = new T_FoodDirection(); //检测说明文档
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["FoodID"] != null)
                {
                    this.LoadData();
                }
            }
        }

        //绑定数据
        private void LoadData()
        {
            if (Request.QueryString["ShowType"].ToString() == "Edit")
            {
                this.Pan_Edit.Visible = true;
                this.Pan_Show.Visible = false;
            }
            else
            {
                this.Pan_Edit.Visible = false;
                this.Pan_Show.Visible = true;
            }

            int FoodID = int.Parse(Request.QueryString["FoodID"]); //知识点ID
            int RawTypeID = 1;//默认为1
            if (Request.QueryString["RawTypeID"] != null)
            {
                RawTypeID = int.Parse(Request.QueryString["RawTypeID"].ToString());
            }
            E_FoodDirection eFoodDirection = tFoodDirection.GetModelList("FoodID=" + FoodID + " and RawTypeID=" + RawTypeID).FirstOrDefault();
            if (eFoodDirection != null)
            {
                this.lab_Contents.Text = eFoodDirection.DirectionContent;
                this.FCK_Content.Value = eFoodDirection.DirectionContent;
            }
        }

        protected void btPost_Click(object sender, EventArgs e)
        {
            int FoodID = int.Parse(Request.QueryString["FoodID"]); //知识点ID
            int RawTypeID = 1;//默认为1
            if (Request.QueryString["RawTypeID"] != null)
            {
                RawTypeID = int.Parse(Request.QueryString["RawTypeID"].ToString());
            }
            bool IsAdd=false;
            E_FoodDirection eFoodDirection = tFoodDirection.GetModelList("FoodID=" + FoodID + " and RawTypeID=" + RawTypeID).FirstOrDefault();
            if (eFoodDirection == null)
            {
                eFoodDirection = new E_FoodDirection();
                IsAdd = true;
            }
            eFoodDirection.FoodID = FoodID;
            eFoodDirection.RawTypeID = RawTypeID;
            eFoodDirection.DirectionContent = this.FCK_Content.Value;
            if (IsAdd) //添加
            {
                tFoodDirection.Add(eFoodDirection);
            }
            else //修改
            {
                tFoodDirection.Update(eFoodDirection);
            }
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('保存成功！');window.location.href='/FoodTesting/FoodDirectionEdit.aspx?FoodID=" + FoodID + "&RawTypeID=" + RawTypeID + "&ShowType=Show';</script>");
        }
    }
}